package com.linkhub.oms.admin.modules.invoice.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.linkhub.oms.admin.modules.invoice.domain.param.InvoiceGenerateParam;
import com.linkhub.oms.admin.modules.invoice.domain.param.InvoiceQueryParam;
import com.linkhub.oms.admin.modules.invoice.domain.vo.InvoiceGenerateVO;
import com.linkhub.oms.admin.modules.invoice.domain.vo.InvoiceListVO;
import com.linkhub.oms.admin.modules.invoice.service.InvoiceBizService;
import com.linkhub.oms.admin.modules.logistic.service.ChannelPriorityBizService;
import com.linkhub.oms.admin.modules.logistic.service.LogisticBizService;
import com.linkhub.oms.admin.modules.satoken.session.LhSessionContext;
import com.linkhub.oms.common.constant.RoleConstant;
import com.linkhub.oms.common.enums.mp.RoleCodeEnum;
import com.linkhub.oms.common.response.DataResponse;
import com.linkhub.oms.common.response.PageDTO;
import com.linkhub.oms.dao.mpservice.IBillListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Jaycle
 * @version 1.0.0
 * @Description InvoiceController.java
 * @createTime 2024/04/29 22:04
 */

@Slf4j
@RestController
@Api(tags = {"账单管理模块"})
@RequestMapping("/Invoice")
@SaCheckLogin
public class InvoiceController {
    @Resource
    private InvoiceBizService invoiceBizService;

    @Resource
    private ChannelPriorityBizService channelPriorityBizService;

    @GetMapping("/list")
    @ApiOperation(value = "查询账单列表接口")
    @SaCheckRole(value = {RoleConstant.CUSTOMER, RoleConstant.EMPLOYEE}, mode = SaMode.OR)
    public DataResponse<PageDTO<InvoiceListVO>> listInvoices( @Validated InvoiceQueryParam invoiceQueryParam ) {
        List<String> userRoles = LhSessionContext.getUserRoles();
        invoiceQueryParam.setCustomRoleFlag(userRoles.contains(RoleCodeEnum.CUSTOMER.getCode()));
        return DataResponse.success(invoiceBizService.listInvoices(invoiceQueryParam));
    }

    @GetMapping("/generate_invoice")
    @ApiOperation(value = "生成账单接口")
    @SaCheckRole(value = {RoleConstant.CUSTOMER, RoleConstant.EMPLOYEE}, mode = SaMode.OR)
    public DataResponse<InvoiceGenerateVO> generateInvoices( @Validated InvoiceGenerateParam invoiceGenerateParam ) {
        return DataResponse.success(invoiceBizService.generateInvoices(invoiceGenerateParam));
    }

}
